﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using NetTaste;
using Renci.SshNet.Security;
using System;

namespace Zocono.WCS.Admin.Common
{
    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false)]
    public class BasicAuthAttribute : ActionFilterAttribute
    {

        /// <summary>
        /// 拦截器
        /// </summary>
        /// <param name="context"></param>
        public override void OnActionExecuting(ActionExecutingContext context)
        {
            context.HttpContext.Request.Cookies.TryGetValue("User_Token", out string value);
            if (!string.IsNullOrEmpty(value))
            {
                context.HttpContext.Response.Cookies.Append("User_Token", value, new CookieOptions
                {
                    Expires = DateTime.Now.AddMinutes(20)
                });
                return;
            }
            context.Result = new RedirectToActionResult("login", "home", null);
            return;

        }
    }

    public class NoSignAttribute : ActionFilterAttribute
    {
    }
}
